/* enum */
import ComponentNameEnum from '@model/enum/ComponentNameEnum'
/* hooks */
import useBizWebSocket from '@src/component/business/BizWebSocket/hooks';
/* model */
import { CommonComponentInstance } from '@model/VC'
/* vue */
//@ts-ignore
import { ComponentInstance, ComponentRenderProxy, defineComponent } from 'vue'

interface BizWebSocketSetupState {
  
}

enum BizWebSocketEventEnum {
  Input = 'input'
}

export type BizWebSocketProps = {
  url: string;
  onConnected?: (ws: WebSocket) => void;
  onDisconnected?: (ws: WebSocket, CloseEvent: CloseEvent) => void;
  onError?: (ws: WebSocket, event: Event) => void;
  onMessage?: (ws: WebSocket, MessageEvent: MessageEvent) => void;
}

export type BizWebSocketInstance = ComponentInstance & BizWebSocketSetupState
export type BizWebSocketVM = ComponentRenderProxy<BizWebSocketProps> & CommonComponentInstance

export default defineComponent<BizWebSocketProps, BizWebSocketSetupState>({
  name: ComponentNameEnum.BizWebSocket,
  props: {
    url: {
      type: String,
      required: true
    },
    onConnected: {
      type: Function,
    },
    onDisconnected: {
      type: Function,
    },
    onError: {
      type: Function,
    },
    onMessage: {
      type: Function,
    }
  },
  setup(props: BizWebSocketProps, { emit }) {
    
    const { initWebSocket } = useBizWebSocket(props)
    const { status, data, send } = initWebSocket()
    
    return {
      status,
      data,
      send
    }
  },
  render() {
    return null as any
  }
})
